package org.ishequ.sms;

import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.Toast;

public class SMSActivity extends Activity {
	private EditText numberEdit;
	private EditText contentEdit;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        numberEdit = (EditText)findViewById(R.id.number);
        contentEdit = (EditText)findViewById(R.id.content);
        findViewById(R.id.send).setOnClickListener(new ButtonClickListener());
    }
    
    public final class ButtonClickListener implements OnClickListener{
		@Override
		public void onClick(View v) {
			SmsManager manager = SmsManager.getDefault();
			String number = numberEdit.getText().toString();
			String content = contentEdit.getText().toString();
			ArrayList<String> texts = manager.divideMessage(content);
			for(String text : texts){
				manager.sendTextMessage(number, null, text, null, null);
			}
			Toast.makeText(SMSActivity.this, R.string.success, Toast.LENGTH_SHORT).show();
		}
    	
    }
}